package com.ssk.sh.core.enums.handler;

import com.ssk.sh.core.enums.ChatTypeEnum;
import java.sql.CallableStatement;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import org.apache.ibatis.type.BaseTypeHandler;
import org.apache.ibatis.type.JdbcType;

/**
 * @author ssk
 * @date 2025/6/12
 **/
public class ChatTypeEnumTypeHandler extends BaseTypeHandler<ChatTypeEnum> {

    @Override
    public void setNonNullParameter(PreparedStatement ps, int i, ChatTypeEnum parameter, JdbcType jdbcType) throws SQLException {
        ps.setString(i, parameter.getValue());
    }

    @Override
    public ChatTypeEnum getNullableResult(ResultSet rs, String columnName) throws SQLException {
        String value = rs.getString(columnName);
        return value == null ? null : ChatTypeEnum.fromValue(value);
    }

    @Override
    public ChatTypeEnum getNullableResult(ResultSet rs, int columnIndex) throws SQLException {
        String value = rs.getString(columnIndex);
        return value == null ? null : ChatTypeEnum.fromValue(value);
    }

    @Override
    public ChatTypeEnum getNullableResult(CallableStatement cs, int columnIndex) throws SQLException {
        String value = cs.getString(columnIndex);
        return value == null ? null : ChatTypeEnum.fromValue(value);
    }
}